package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.RadioPageModuleRadioData;
import com.rjwh.dingdong.client.util.ViewHolder;
import com.rjwh.dingdong.client.widget.RoundImageView;

/**
 * @author Kay
 * @ClassName RadioPageModuleBookGvAdapter
 * @Description
 * @date 2016-10-27
 * @history 2016-10-27 author: description:
 */
public class RadioPageModuleBookGvAdapter extends AdapterBase<RadioPageModuleRadioData> {

    private Context mContext;

    public RadioPageModuleBookGvAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    protected View getExView(int position, View convertView, ViewGroup parent) throws Exception {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.radio_page_module_grid_item, parent, false);
        }
        RoundImageView radioPageModuleGridItemImg = ViewHolder.get(convertView, R.id.radio_page_module_grid_item_img);
        TextView radioPageModuleGridItemTv = ViewHolder.get(convertView, R.id.radio_page_module_grid_item_tv);

        RadioPageModuleRadioData radioPageModuleRadioData = getList().get(position);
        String coverurl = radioPageModuleRadioData.getCoverurl();
        String subtitle = radioPageModuleRadioData.getSubtitle();

        if (coverurl != null) {
            Glide.with(mContext).load(coverurl).dontAnimate().placeholder(R.drawable.icon_pic_holder).error(R.drawable.icon_pic_holder).diskCacheStrategy(DiskCacheStrategy.ALL).into(radioPageModuleGridItemImg);
        }
        if (!AsStrUtils.isEmpty(subtitle)) {
            radioPageModuleGridItemTv.setText(subtitle);
        }

        return convertView;
    }
}
